package net.spunofbook;

import java.util.List;
import net.spunofbook.modelo.ClienteRepositorio;
import net.spunofbook.negocio.Cliente;
import net.spunofbook.negocio.ClienteAdapter;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class TelaCliente extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.tela_cliente);	-> Mudou a estrutura n�o precisa mais disto.
		
		ClienteRepositorio banco = new ClienteRepositorio(this);
		
		List<Cliente> clientes = banco.buscarTodosOsClientes();
		
		setListAdapter(new ClienteAdapter(this, clientes));		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getMenuInflater().inflate(R.menu.tela_cliente, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		Context v = getBaseContext();
		switch (item.getItemId()) {
		case R.id.telaClienteMenu_inicio:
			chamarTelaInicio(v);
			break;
		case R.id.telaClienteMenu_cadastrar:
			chamarTelaCadastro(v);
			break;
		default:
			break;
		}
		return true;
	}
	
	private void chamarTelaInicio(Context context) {
		startActivity(new Intent(context, TelaPrincipal.class));
		finish();
	}
	
	private void chamarTelaCadastro(Context context){
		startActivity(new Intent(context, TelaClienteCadastro.class));
		finish();
	}
}
